//
//  UPShopCartCell.m
//  LoveFreshBee
//
//  Created by wyzc on 16/6/17.
//  Copyright © 2016年 叶落知秋. All rights reserved.
//

#import "UPShopCartCell.h"
#import "UPShopingCartMOdel.h"
#import <UIImageView+WebCache.h>
@interface UPShopCartCell ()
/**
 *  存放占位图片
 */
@property(nonatomic,strong)UIImage *imageHolder;
/**
 *  选中按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *selectedBtn;
/**
 *  精选
 */
@property (weak, nonatomic) IBOutlet UILabel *jingXuanLabel;
/**
 *  图片
 */
@property (weak, nonatomic) IBOutlet UIImageView *leftImageView;
/**
 *  名字
 */
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
/**
 *  价格
 */
@property (weak, nonatomic) IBOutlet UILabel *pricelabel;
/**
 *  -号按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *incraseBtn;
/**
 *  数量
 */
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
/**
 *  +号按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *reduceBtn;

@end
@implementation UPShopCartCell



- (void)awakeFromNib {
    [super awakeFromNib];
    //添加占位图片
    self.imageHolder=[UIImage imageNamed:@"v2_placeholder_square"];
}
-(void)setModel:(UPShopingCartMOdel *)model
{
    _model=model;
    
    NSURL *url=[NSURL URLWithString:model.img];
    
    [self.leftImageView sd_setImageWithURL:url placeholderImage:self.imageHolder];
    
    self.nameLabel.text=model.name;
    
    self.numLabel.text=@(model.num).stringValue;
    
    self.pricelabel.text=[NSString stringWithFormat:@"￥%g",model.price];
    self.selectedBtn.selected=!model.selected;
}

/**
 * cell中选择按钮的点击事件
 */
- (IBAction)selectedBtnClick:(id)sender {
    
   UIButton *selectedBtn=sender;
   selectedBtn.selected=!selectedBtn.selected;
    self.model.selected=!self.model.selected;
    //刷新当前的tableview
    //通知
    NSNotificationCenter *center=[NSNotificationCenter defaultCenter];
    [center postNotificationName:@"CellClick" object:self];
//    UITableView *tableView=(UITableView *)self.superview.superview;
//    [tableView reloadData];
}
@end
